﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Qplus.protocol
{
    public class DataUtil
    {

        /** Gets int value */
        public static int getInt(byte b)
        {
            return b & 0xff;
        }

        /**
	    * 注释：字节数组到short的转换！
	    * 
	    * @param b
	    * @return
	    */
        public static int byteToShort(byte one, byte two)
        {
            return (((two & 0xff) << 8) | one & 0xff);
        }


        public static long byteToInt(byte a, byte b, byte c, byte d)
        {
            // TODO 4个字节转int
            return ((d & 0xff) << 24) | ((c & 0xff) << 16) |
                    ((b & 0xff) << 8) | (a & 0xff);
        }

        public static byte[] twoToBytes(int val)
        {
            // TODO 转换
            byte[] data = new byte[2];
            data[0] = (byte)(val);
            data[1] = (byte)(val >> 8);
            return data;
        }


        public static byte[] fourToBytes(long val)
        {
            // TODO 转换
            byte[] data = new byte[4];
            data[0] = (byte)(val);
            data[1] = (byte)(val >> 8);
            data[2] = (byte)(val >> 16);
            data[3] = (byte)(val >> 24);
            return data;
        }

    }
}
